<!DOCTYPE html>
<html>

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">


    <title>路径管理</title>
    <meta name="keywords" content="">
    <meta name="description" content="">

    <link rel="shortcut icon" href="favicon.ico"> <link href="__CSS__/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="__CSS__/font-awesome.css?v=4.4.0" rel="stylesheet">
    <link href="__CSS__/animate.css" rel="stylesheet">
    <link href="__CSS__/style.css?v=4.1.0" rel="stylesheet">

</head>

<body class="gray-bg">
<div><h1>路径管理</h1></div>

<div id="xmTanImg">

</div>

<div class="wrapper wrapper-content animated fadeInRight">
    <div class="container">
            <form action="{:url('Website/add_course')}" method="post" enctype="multipart/form-data" >
                <div class="row">
                    <div class="btn-group">
                        <button type="button" class="btn btn-default">课程</button>
                        <button type="button" class="btn btn-default dropdown-toggle"
                                data-toggle="dropdown">
                            <span class="caret"></span>
                            <span class="sr-only">切换下拉菜单</span>
                        </button>
                        <ul class="dropdown-menu heightall" role="menu">
                            {volist name="class" id="value1"}
                            <li  onclick="changges(1,'{$value1.record_name}')">{$value1.record_name}</li>
                            {/volist}
                        </ul>
                    </div>
                    <input type="hidden" name="picture_id" value="{$picture_id}">
                    <select   name="course_id" id="select" style="display: inline-block;"  >
                    </select>
         <div class="col-md-2 col-xs-6  ">
            <button class="btn" id="button1">添加</button>
        </div>
        </div>
            </form>
        </div>
    </div>



        <div class="row">
                <table class="table table-hover table-bordered text-center">
                    <thead >
                    <tr >
                        <th class="text-center">图片id</th>
                        <th class="text-center">课程名字</th>
                        <th class="text-center">管理操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    {volist name="course" id="value"}
                    <tr>
                        <td>{$value.id}</td>
                        <td>{$value.record_name}</td>
                        <td>
                            <button class="btn btn-danger" onclick="deletes_course('{$value.id}','{$picture_id}')">删除</button>

                        </td>


                    </tr>
                    {/volist}
                    </tbody>
                </table>

        </div>
    </div>


<!-- 全局js -->
<script src="__JS__/jquery.min.js?v=2.1.4"></script>
<script src="__JS__/bootstrap.min.js?v=3.3.6"></script>
<script src="__JS__/jquery.validate.js"> </script>


<!-- 自定义js -->
<script>
    var deleteurl="{:url('Website/deletes_course')}";
    function deletes_course(course_id,picture_id) {
        if(confirm("你确定要删除这个吗  ？！")){
        $.ajax({
            url:deleteurl,
            type:"post",
            dataType:"text",
            data:{
                course_id:course_id,
                picture_id:picture_id
            },
            success:function (data) {
                if(data=="1"){
                    alert("删除成功")
                   history.go(0)
                }else{
                    alert("删除失败")
                }
            },
            error:function (e) {
                alert(e.response)
            }


        })
        }
    }
    function submits(obg) {
//        alert(123)
        alert($(obg).siblings().eq(1).val());
        if($(obg).siblings("input").val()==""){
            alert("你还没选择文件哦");
            return false;
        }else{
            return false;
        }
    }


    $(".files").on("change", function () {
        var objUrl = getObjectURL(this.files[0]); //获取图片的路径，该路径不是图片在本地的路径
        if (objUrl) {
            alert(objUrl);
            $("#xmTanImg").css("background-image", "url('"+objUrl+"')"); //将图片路径存入src中，显示出图片
//            alert(objUrl);
        }else{
        }
        $('#xmTanImg').css('display', 'block');
    });
    function getObjectURL(file) {
        var url = null;
        if (window.createObjectURL != undefined) { // basic
            url = window.createObjectURL(file);
        } else if (window.URL != undefined) { // mozilla(firefox)
            url = window.URL.createObjectURL(file);
        } else if (window.webkitURL != undefined) { // webkit or chrome
            url = window.webkitURL.createObjectURL(file);
        }
        return url;
    }
    var chengeurl="{:url('Website/addchange')}";
    function changges(selectid,classname) {

        $.ajax({
            url: chengeurl,
            type: "post",
            dataType: "json",
            data: {
                classname:classname
            },
            success: function (data) {
                $("#select"+selectid).empty();
                for (var i = 0; i < Object.keys(data).length; i++) {  //获取data长度   循环遍历出来
                    $("#select").append('<option value=' + data[i].id + '>' + data[i].record_name + '</option>')
                }
            },
            error: function (e) {
                alert(e.response)
            }
        })
    }
</script>







</body>

</html>
